<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>音频录音</title>
</head>
<body>
  <audio controls autoplay style='display: none;'></audio>
  <div>
    <div>开始录音</div>
    <div>暂停录音</div>
    <div>恢复录音</div>
    <div>结束录音</div>
    <div>上传录音</div>
    <div>播放录音</div>
  </div>
  <script src="./index.js"></script>
  <script src="./HZRecorderForm.js"></script>
  <script>
    /**
     * 录音前准备 检查录音设备是否到位
     */
    this.readyRecording = async function() {
      let recorder // 表示录音类实例
      // 流模式下ready钩子 res 为录音类实例 或者 false
      await HZRecorder.ready().then(res => {
        recorder = res
      })
      // 表单模式下ready钩子 res 为录音类实例 或者 false
      await HZRecorderForm.ready().then(res => {
        recorder = res
      })
      return recorder
    }
    /**
     * 开始录音
     */
    this.startRecording = function() {
      recorder.start();
    }
    /**
     * 结束录音
     */
    this.stopRecording = function() {
      recorder.end();
    }
    /**
     * 播放录音
     */
    this.playRecording = function() {
      recorder.play(audio);
    }
    /**
     * 继续录音
     */
    this.resumeRecord = function() {
      recorder.again();
    }
    /**
     * 暂停录音
     */
    this.pauseRecord = function() {
      recorder.stop();
    }
    /**
     * 重新录音
     */
    this.reRecord = function() {
      this.startRecording()
    }
    /**
     * 上传录音
     */
    this.uploadRecord = function() {
      // 流模式下上传
      recorder.upload(url, succ, fail)
      // 表单模式下上传
      recorder.upload(url, succ, fail)
    }

  </script>
</body>
</html>